package com.linwen.javase.desgin_pattern.BigTalkDesignPattenJAVACode._0._3工厂;

import java.util.Optional;

/**
 * @ClassName AnimalFactory
 * @Description TODO
 * @Author zero
 * @DATE 2023/7/9 7:32 PM
 * @Version 1.0
 */
public class AnimalFactory {
    public static Animal createAnimal(String animalCategory,String name,int shoutNum){
        Animal animal = null;
        switch (animalCategory){
            case "猫":
                animal = new Cat(name);
                break;
            case "狗":
                animal = new Dog(name);
                break;
            default:break;

        }
        Optional.ofNullable(animal).ifPresent(item-> item.setShoutNum(shoutNum));
        return animal;
    }
}
